package lazy2.util;

public class KeywordChecker extends BinaryChecker {
	class CharDataIndexStructure extends DataIndexStructure {
		char[] charData;
		int index = 0;
	}
	public KeywordChecker() {}
	public KeywordChecker(String keyword) {addKeyword(keyword);}
	
	private void addCheckData(String keyword) {
		if(keyword!=null) {
			CharDataIndexStructure d = new CharDataIndexStructure();
			d.charData = keyword.toCharArray();
			d.data = keyword.getBytes();
			checkDatas.add(d);
		}
	}
	
	public void addKeyword(String keyword) {
		addCheckData(keyword);
	}
	public void addKeywordIgnoreCase(String keyword) {
		addCheckData(keyword.toLowerCase());
		addCheckData(keyword.toUpperCase());
	}
	public boolean isChecked(char c) {
		for(DataIndexStructure checkData:checkDatas) {
			if(!(checkData instanceof CharDataIndexStructure)) continue;
			if(((CharDataIndexStructure)checkData).charData[checkData.index]==c) {
				++checkData.index;
				if(checkData.index==checkData.data.length) {
					checkData.index = 0;
					return true;
				}
			} else {
				checkData.index = 0;
			}
		}
		return false;
	}
}
